export const createDraw = ({type,source,success}) => {
let geomentryFunction = null
let maxPoints = null
if(type === 'Square') {
  type = 'Circle'
  geomentryFunction = ol.interaction.Draw.createRegularPolygon(4)
}
if(type === 'Box') {
  type = 'LineString'
  geomentryFunction = (coordinate,geometry) => {
    if(!geometry) {
      geometry = new ol.geom.Polygon(null)
    }
    const start = coordinate[0]
    const end = coordinate[1]
    geometry.setCoordinates([
      [start,[start[0],end[1]],end,[end[0],start[1]],start]
    ])
    return geometry
  }
  maxPoints = 2
}
let draw = new ol.interaction.Draw({
  type,
  source,
  geomentryFunction,
  maxPoints,
})
if(typeof success === 'function') {
  draw.on('drawend',(e) => {
    success(e.feature)
  })
}
return draw
}
